﻿#pragma once
//
// sender.cpp
// udp组播发送类
//
#include <iostream>
#include <sstream>
#include <string>
#include <boost/asio.hpp>
#include "sender.h"

class multicast_sender
{
public:
    multicast_sender(boost::asio::io_context& io_context
        , const boost::asio::ip::address& multicast_address
        , const unsigned short  multicast_port
        , const boost::asio::ip::udp::endpoint& bind_endpoint);
    ~multicast_sender();
    // 异步发送，没发送完之前不能修改data
    void async_send_to(const std::vector<char>& data
        , std::function<void (boost::system::error_code ec, std::size_t)> handler);
    void async_send_to(const char* data, size_t length
        , std::function<void(boost::system::error_code ec, std::size_t)> handler);
    void async_send_to(const std::string& data
        , std::function<void(boost::system::error_code ec, std::size_t)> handler);

private:
    multicast_sender(const multicast_sender&) = delete;
    struct multicast_sender_impl;
    multicast_sender_impl* impl{ nullptr };
};
